﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web.UI;
using System.ComponentModel;

namespace Lswweb.Controls
{
    /// <summary>
    /// 一个页面只能有一个Resize控件
    /// </summary>
    public class Resize : Control
    {
        #region 成员字段和造方法

        public Resize()
        {
        }

        #endregion

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);

            Page.ClientScript.RegisterStartupScript(typeof(Resize), this.ClientID, "$(\"#" + ResizeControlId + "\").Resize({reduceWidth: " + ReduceWidth + ",reduceHeight: " + ReduceHeight + ",orientationMode: \"" + OrientationMode.ToString() + "\", referToControlId: \"" + ReferToControlId + "\"});", true);
        }


        #region 属性

        [Description("需要进行自动调整大小的控件Id。")]
        public string ResizeControlId { get; set; }

        [Description("缩小高度。")]
        public int ReduceHeight { get; set; }

        [Description("缩小宽度。")]
        public int ReduceWidth { get; set; }

        [Description("自动调整大小参照的控件Id，默认是元素body。注：这个参数控件必须要设置一个大小，不然resize事件不会响应。")]
        public string ReferToControlId { get; set; }

        [Description("控件自动调整大小的方向。")]
        public ResizeOrientationMode OrientationMode { get; set; }

        #endregion
    }

    public enum ResizeOrientationMode
    {
        All,
        Width,
        Height
    }
}
